import { wxRequest } from '../../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    assessStatistics: Object,
    assessList: Array,
    gdsId: String,
    flagMore: Boolean
  },

  data: {
    imgUrl: app.globalData.imgUrl,
    uploadUrl: wx.getStorageSync('uploadUrl'),
    assessList: [],
    assessStatistics: {},
    flagMore: false
  },
  attached() {

  },

  ready() {
    this.getDetail()
  },


  methods: {
    //预览户型图
    imageList: function (e) {
      let current = this.data.uploadUrl + e.target.dataset.src;
      let urls = e.target.dataset.urls;
      if (urls && urls.length) {
        for (var i = 0; i < urls.length; i++) {
          urls[i] = this.data.uploadUrl + urls[i].imgPath
        };
      }
      wx.previewImage({
        current: current, // 当前显示图片的http链接
        urls: urls // 需要预览的图片http链接列表
      });
    },

    //评价
    moreAssess: function (e) {
      var item = e.target.dataset.assessStatistics;
      var type = e.target.dataset.type || ''
      wx.setStorageSync('assessStatistics', item)
      if (this.data.flagMore) {
        wx.navigateTo({
          url: '/pages/good/detail/assess?gdsId=' + this.data.gdsId + '&type=' + type,
        })
      } else {
        this.triggerEvent('typeChange', type)
      }


    },

    //获取产品详情
    getDetail: function () {
      _wxRequest.wxAjax({
        url: app.globalData.apiUrl + '/gds/goods/detail2?id=' + this.data.gdsId,
        method: 'POST'
      }, (res) => {
        var detailVo = res.vo;
        this.setData({
          assessStatistics: detailVo.assessStatistics,
        })
      })

    },
  }
})
